package org.squabble.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity(name="systemProperty")
@Table(name = "SYSTEM_PROPERTY")
@DiscriminatorColumn(name = "CLASS", discriminatorType = DiscriminatorType.STRING)
public abstract class SystemProperty implements Serializable {

	private static final long serialVersionUID = -7997460213431797759L;

	@Id
	@Column(name = "PROPERTY_NAME", nullable=false)
	private String name;

	public SystemProperty() {
		super();
	}
	
	public SystemProperty(String name, Object value) {
		super();
		this.name = name;
		setValue(value);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setValue(Object value) {

		setObject(value);
	}

	public Object getValue() {
		Object value = getObject();

		return value;
	}

	// abstract methods

	/**
	 * is true if this variable-instance supports the given value, false
	 * otherwise.
	 */
	public abstract boolean isStorable(Object value);

	/**
	 * is the value, stored by this variable instance.
	 */
	protected abstract Object getObject();

	/**
	 * stores the value in this variable instance.
	 */
	protected abstract void setObject(Object value);

}
